using System;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Auto.Data.DBUtility;
using System.Data;
using Auto.Data.Systems.BLL;

namespace BaseSystem
{
    public partial class topSystems : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsCallback)
            {
                BindDBMenu();
            }
        }

        private void BindDBMenu()
        {
            //string Sql = "SELECT SysID FROM _Systems;";
            //DataTable dt = DbHelper.ExecuteQuery(Sql).Tables[0];
            //this.rSystems.DataSource = Auto.Data.Systems.BLL.Systems.Instance.Select();
            //this.rSystems.DataBind();
            //int i = dt.Rows.Count;
            Systems s = new Systems();
            DataTable dtSystems = s.GetSystems();
            int i = dtSystems.Rows.Count;

            if (i > 0)
            {
                for (int j = 0; j < i; j++)
                {
                    //Response.Write(dt.Rows.Count + "<br>");
                    HtmlAnchor a = new HtmlAnchor();
                    a.HRef = "LoadMenu.aspx?SysID=" + dtSystems.Rows[j]["SysID"].ToString();
                    a.Target = "menuFrame";
                    a.InnerHtml = dtSystems.Rows[j]["SysID"].ToString();
                    a.Attributes["style"] = " width:100%; display:block ";
                    //a.InnerHtml = "<span>" + dt.Rows[j]["SystID"].ToString() + "</span>";
                    //if (a.HRef == "_System")
                    //{
                    //    a.Attributes["class"] = "current"; //Whether is the selected item
                    //}

                    //a.Attributes["class"] = "normal";

                    HtmlGenericControl li = new HtmlGenericControl("li");
                    li.Controls.Add(a);
                    li.Attributes["class"] = "normal";
                    li.Attributes["style"] = "width:" + 100 / i + "%";  //width:100%; display:block
                    ulSystems.Controls.Add(li);


                    //HtmlGenericControl ul = new HtmlGenericControl("ul");
                    //ul.Controls.Add(li);
                    //ulMenu.Controls.Add(ul);
                }
            }

 
        }


        //private void BindMenu()
        //{
        //    foreach (SiteMapNode adminNode in SiteMap.Providers["SecuritySiteMap"].RootNode.ChildNodes)
        //    {
        //        if (adminNode.IsAccessibleToUser(HttpContext.Current))
        //        {
        //            if (!Request.RawUrl.ToUpperInvariant().Contains("/ADMIN/") && (adminNode.Url.Contains("xmanager") || adminNode.Url.Contains("PingServices")))
        //                continue;

        //            HtmlAnchor a = new HtmlAnchor();
        //            a.HRef = adminNode.Url;

        //            a.InnerHtml = "<span>" +adminNode.Title + "</span>";
        //            if (Request.RawUrl.EndsWith(adminNode.Url, StringComparison.OrdinalIgnoreCase))
        //                a.Attributes["class"] = "current";
        //            HtmlGenericControl li = new HtmlGenericControl("li");
        //            li.Controls.Add(a);
        //            ulSystems.Controls.Add(li);
        //        }
        //    }

        //    //if (!Request.RawUrl.ToUpperInvariant().Contains("/ADMIN/"))
        //    //    AddItem(Resources.labels.changePassword, Utils.RelativeWebRoot + "login.aspx");
        //}

        //public void AddItem(string text, string url)
        //{
        //    HtmlAnchor a = new HtmlAnchor();
        //    a.InnerHtml = "<span>" + text + "</span>";
        //    a.HRef = url;

        //    HtmlGenericControl li = new HtmlGenericControl("li");
        //    li.Controls.Add(a);
        //    ulSystems.Controls.Add(li);
        //}



    }
}